﻿#ifndef PUBLICDATA_H
#define PUBLICDATA_H
#include <vector>
#include <map>
#include <utility>
using std::vector;
using std::map;
using std::pair;
//#include <wx/chartype.h>
#include <wx/listctrl.h>
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include "sqlite3.h"


extern sqlite3 *g_db; // connect object
#define DefaultConv wxConvUTF8//sqlite中存放的text的编码格式(按此格式读取与写稿数据库),默认UTF8
//#define DefaultConv wxConvLibc
#define ToDefaultConv(str) ((str).mb_str(DefaultConv).data())
#define LenDefaultConv(str) strlen(ToDefaultConv(str))
extern wxString g_userid;
extern wxString g_username;
extern int g_userpermit;
extern const wxChar* g_DBFILENAME;//数据库文件名
#define ADDMODEL 1
#define MODMODEL 2
//select显示在控件中的格式
enum {
    FILED_INT=1,
    FILED_FLOAT,
    FILED_TEXT,
    FILED_DT,//时间跟日期,格式为YYYY-MM-DD HH:mm:ss
    FILED_DATE,//日期，格式为YYYY-MM-DD
    FILED_TIME,//时间，格式为HH:mm:ss
    FILED_BLOB,
};

bool filecopy(const char *srcFile,const char *dstFile);
bool open_db(const wxString& filepath, sqlite3 **db);
void close_db(sqlite3 **db);

bool SelFromDb(const vector<pair<wxString,int> >&fileds,const wxString& tablename,
               const map<wxString,wxString>*condition, const wxString& other, wxListCtrl* listctrl);
bool DelFromDb(const wxString& tablename,const map<wxString,wxString>*condition);
bool ModToDb(const map<wxString,wxString>&fileds,const wxString& tablename,const map<wxString,wxString>*condition);
bool AddIntoDb(const map<wxString,wxString>&fileds,const wxString& tablename);

const vector<pair<wxString,int> > GetTypeName_ID(const wxString &condition);
const vector<pair<wxString,wxString> > GetUserName_ID(const wxString &condition);
const vector<pair<wxString,wxString> > GetMenuName_ID(const wxString &condition);
const vector<pair<wxString,wxString> > GetFiled_CHS_Name(const wxString& tablename);

int loadOrSaveDb(sqlite3 *pInMemory, const char *zFilename, int isSave);
int backupDb(sqlite3 *pDb, const char *zFilename, void(*xProgress)(int, int));

#endif // PUBLICDATA_H
